package cn.taichoo.server.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import com.ruoyi.common.core.web.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import cn.taichoo.server.mapper.PackGuideMapper;
import cn.taichoo.server.domain.PackGuide;
import cn.taichoo.server.service.IPackGuideService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ruoyi.common.security.utils.SecurityUtils;

import javax.annotation.Resource;

/**
 * 手机打包业务-引导页设置Service业务层处理
 *
 * @author Wuzh
 * @date 2025-03-17
 */
@Service
@Slf4j
public class PackGuideServiceImpl extends ServiceImpl<PackGuideMapper, PackGuide> implements IPackGuideService {

    @Resource
    private PackGuideMapper packGuideMapper;

    /**
     * 查询手机打包业务-引导页设置
     *
     * @param id 手机打包业务-引导页设置主键
     * @return 手机打包业务-引导页设置
     */
    @Override
    public PackGuide selectPackGuideById(Long id) {
        return packGuideMapper.selectPackGuideById(id);
    }

    /**
     * 查询手机打包业务-引导页设置列表
     *
     * @param packGuide 手机打包业务-引导页设置
     * @return 手机打包业务-引导页设置
     */
    @Override
    public List<PackGuide> selectPackGuideList(PackGuide packGuide) {
        return packGuideMapper.selectPackGuideList(packGuide);
    }

    /**
     * 新增手机打包业务-引导页设置
     *
     * @param packGuide 手机打包业务-引导页设置
     * @return 结果
     */
    @Override
    public AjaxResult insertPackGuide(PackGuide packGuide) {
        packGuide.setCreateBy(SecurityUtils.getUserId());
        boolean save = this.save(packGuide);
        if (!save) {
            log.error("{}-新增{}失败！", LocalDateTime.now(), packGuide.getId());
            throw new RuntimeException("插入失败！" );
        }
        return AjaxResult.success();
    }

    /**
     * 修改手机打包业务-引导页设置
     *
     * @param packGuide 手机打包业务-引导页设置
     * @return 结果
     */
    @Override
    public AjaxResult updatePackGuideById(PackGuide packGuide) {
        boolean b = this.updateById(packGuide);
        if (!b) {
            log.error("{}-修改{}失败！", LocalDateTime.now(), packGuide.getId());
            throw new RuntimeException("修改失败！" );
        }
        return AjaxResult.success();
    }

    /**
     * 删除手机打包业务-引导页设置
     *
     * @param id 手机打包业务-引导页设置
     * @return 结果
     */
    @Override
    public AjaxResult deletePackGuideById(Long id) {
        boolean update = this.update(new LambdaUpdateWrapper<PackGuide>().
                set(PackGuide::getDeleted, 1).
                eq(PackGuide::getId, id));
        if (!update) {
            log.error("{}-删除{}失败！", LocalDateTime.now(), id);
            throw new RuntimeException("删除失败！" );
        }
        return AjaxResult.success();
    }

}
